package com.yc.yyds.util;

import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.net.URLEncoder;

@WebFilter(filterName = "GLYloginFilter",value = {"/houtai/user.html","/houtai/arrange.html","/houtai/cinema.html","/houtai/movie.html","/houtai/indent.html","/houtai/AboutMe.html"})
public class GLYloginFilter implements Filter {
    public void init(FilterConfig config) throws ServletException {
    }

    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {

       HttpServletRequest httpServletRequest = (HttpServletRequest)request;
        HttpSession session=httpServletRequest.getSession();

        if(session.getAttribute("usernames")==null){
            HttpServletResponse httpServletResponse=(HttpServletResponse)response;
            String url= URLEncoder.encode("login.html","UTF-8");
            httpServletResponse.sendRedirect(url);
            return;
        }
          chain.doFilter(request, response);
    }
}
